import {
    RELOAD_MOCK_SERVER_TRIGGER,
    RELOAD_MOCK_SERVER_FULFILLED,
    RELOAD_MOCK_SERVER_REJECTED,
    SET_SERVER_TIME_TRIGGER,
    SET_SERVER_TIME_FULFILLED
} from '../../common/constants/mock-server-constants.js';

const defaultState = {
    // 是否在线
    online: false,
    // 不用服务器时间
    time: false
};

export {
    RELOAD_MOCK_SERVER_TRIGGER,
    RELOAD_MOCK_SERVER_FULFILLED,
    RELOAD_MOCK_SERVER_REJECTED,
    SET_SERVER_TIME_TRIGGER,
    SET_SERVER_TIME_FULFILLED
}

/**
 * API Mock Reducer
 * @param {Object} state
 * @param {Object} action
 */
export default function APIMockeducer(state = defaultState, action) {
    switch (action.type) {
        // API Mock 成功开启
        case RELOAD_MOCK_SERVER_FULFILLED:
            return {
                ...state,
                online: true
            };
        // API Mock 准备重启
        case RELOAD_MOCK_SERVER_TRIGGER:
        // API Mock 未成功开启
        case RELOAD_MOCK_SERVER_REJECTED:
            return {
                ...state,
                online: false
            };
        // 开始设置服务器时间
        case SET_SERVER_TIME_TRIGGER:
            return {
                ...state,
                time: false
            };
        // 成功设置服务器时间
        case SET_SERVER_TIME_FULFILLED:
            return {
                ...state,
                time: true
            };
        default:
            return state;
    }
}
